var t = wx.createCanvasContext("photoCombine");

Page({
    data: {
        height: 0,
        heightForCanvas: 0,
        downNum: 0
    },
    onLoad: function(a) {
        for (var e = this, o = e.data, n = JSON.parse(a.imageUrls), h = (n.length, wx.getSystemInfoSync().windowWidth, 
        0); h < n.length; h++) {
            var i = n[h];
            wx.getImageInfo({
                src: i,
                success: function(a) {
                    var h = a.width, i = a.height;
                    o.downNum = o.downNum + 1, console.log(a);
                    var s = wx.getSystemInfoSync().windowWidth;
                    h > s && (h = s, i = i / a.width * h), t.drawImage(a.path, (s - h) / 2, o.heightForCanvas, h, i), 
                    o.heightForCanvas = o.heightForCanvas + i, e.setData({
                        height: o.heightForCanvas
                    }), o.downNum == n.length && t.draw();
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    toSavePic: function() {
        var t = wx.getSystemInfoSync().windowWidth, a = this, e = a.data;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: t,
            height: e.heightForCanvas,
            destWidth: 2 * t,
            destHeight: 2 * e.heightForCanvas,
            canvasId: "photoCombine",
            success: function(t) {
                a.setData({
                    shareImagePath: t.tempFilePath
                }), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath
                }), wx.showToast({
                    title: "保存成功",
                    icon: "success"
                });
            }
        });
    },
    toSharePic: function() {
        var t = wx.getSystemInfoSync().windowWidth, a = this.data;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: t,
            height: a.heightForCanvas,
            destWidth: 2 * t,
            destHeight: 2 * a.heightForCanvas,
            canvasId: "photoCombine",
            success: function(t) {
                wx.navigateTo({
                    url: "/pages/sharePhoto/sharePhoto?imageUrl=" + t.tempFilePath
                });
            }
        });
    }
});